/*
ID:luongho3
LANG:C++
TASK:transform
*/
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
typedef vector<string> sVector;

ifstream fin("transform.in");
ofstream fout("transform.out");
int patternSize;
sVector beforePattern,afterPattern;
sVector readPattern(int patternSize) {
        sVector result;
        string line;
        while (patternSize>0) {
              fin>>line;
              result.push_back(line);
              patternSize--;      
        }
        return result;
}
sVector rotate90(sVector pattern) {
        sVector result=pattern;
        int i,j,lastIndex;
        lastIndex=pattern.size()-1;
        for (i=0;i<=lastIndex;++i) {
            for (j=0;j<=lastIndex;++j) {
                result[j][lastIndex-i]=pattern[i][j];
                }
        }        
        return result;
}
sVector rotate180(sVector pattern) {
        sVector result=rotate90(rotate90(pattern));
        return result;
}
sVector rotate270(sVector pattern) {
        sVector result=rotate90(rotate180(pattern));
        return result;        
}

sVector reflect(sVector pattern) {
        sVector result=pattern;
        int i,j,lastIndex;
        lastIndex=pattern.size()-1;        
        for (i=0;i<=lastIndex;++i) {
            for (j=0;j<=lastIndex;++j) {
                result[i][lastIndex-j]=pattern[i][j];
            }    
        }
        return result;
}
sVector combine90(sVector pattern) {
        return rotate90(reflect(pattern));                
}
sVector combine180(sVector pattern) {
        return rotate180(reflect(pattern));       
}
sVector combine270(sVector pattern) {
        return rotate270(reflect(pattern));        
}
bool equal(sVector src,sVector dst) {
     int i,lastIndex;
     lastIndex=src.size()-1;
     for (i=0;i<=lastIndex;++i) {
         if (src[i]!=dst[i])    
            return false;
     }
     return true;
}
main() {
       fin>>patternSize;
       beforePattern=readPattern(patternSize);
       afterPattern=readPattern(patternSize);
       if (equal(rotate90(beforePattern),afterPattern)) {
          fout<<"1\n";                                                    
       }
       else if (equal(rotate180(beforePattern),afterPattern)) {
            fout<<"2\n";
       }
       else if (equal(rotate270(beforePattern),afterPattern)) {
            fout<<"3\n";     
       }
       else if (equal(reflect(beforePattern),afterPattern)) {
            fout<<"4\n";     
       }
       else if (equal(combine90(beforePattern),afterPattern)
               ||equal(combine180(beforePattern),afterPattern)
               ||equal(combine270(beforePattern),afterPattern)) {
            fout<<"5\n";     
       }
       else if (equal(beforePattern,afterPattern)) {
            fout<<"6\n";     
       }
       else {
            fout<<"7\n";     
       }
       return 0;
}
